package Obj;

import Main.GameBegin;

import java.awt.*;

public class BgObj extends GameObj {
    public BgObj() {
    }

    public BgObj(Image img, int width, int height, int x, int y, double speed, GameBegin gameBegin) {
        super(img, width, height, x, y, speed, gameBegin);
    }

    @Override
    public void paintSelf(Graphics g) {
        // 更新 Y 坐标
        this.y += speed;

        // 如果整个图片已经完全移出屏幕下方，则重置到上方继续滚动
        if (this.y > this.gameBegin.getHeight()) {
            this.y = 0;
        }

        // 绘制图像
        g.drawImage(this.img, this.x, this.y, this.width, this.height, null);
        g.drawImage(this.img, this.x, this.y - this.height, this.width, this.height, null);
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
